﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package org.aswing {
    import flash.events.*;
    import flash.display.*;
    import org.aswing.geom.*;
    import org.aswing.event.*;

    public class AWSprite extends Sprite {

        private var foregroundChild:DisplayObject;
        private var backgroundChild:DisplayObject;
        private var clipMasked:Boolean = false;
        private var clipMaskRect:IntRectangle;
        private var content:Sprite;
        private var maskShape:Shape;
        private var usingBitmap:Boolean;
        private var pressedTarget:DisplayObject;

        public function AWSprite(_arg1:Boolean=false){
            focusRect = false;
            this.usingBitmap = false;
            this.clipMaskRect = new IntRectangle();
            this.setClipMasked(_arg1);
            addEventListener(MouseEvent.MOUSE_DOWN, this.__awSpriteMouseDownListener);
        }
        protected function d_addChild(_arg1:DisplayObject):DisplayObject{
            return (super.addChild(_arg1));
        }
        protected function d_addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
            return (super.addChildAt(_arg1, _arg2));
        }
        override public function addChildAt(_arg1:DisplayObject, _arg2:int):DisplayObject{
            if (this.usingBitmap){
                return (this.content.addChildAt(_arg1, _arg2));
            };
            return (this.d_addChildAt(_arg1, _arg2));
        }
        protected function d_removeChild(_arg1:DisplayObject):DisplayObject{
            return (super.removeChild(_arg1));
        }
        protected function isChild(_arg1:DisplayObject):Boolean{
            if (this.usingBitmap){
                return ((_arg1.parent == this.content));
            };
            return ((_arg1.parent == this));
        }
        override public function removeChild(_arg1:DisplayObject):DisplayObject{
            if (this.usingBitmap){
                return (this.content.removeChild(_arg1));
            };
            return (this.d_removeChild(_arg1));
        }
        protected function d_removeChildAt(_arg1:int):DisplayObject{
            return (super.removeChildAt(_arg1));
        }
        override public function removeChildAt(_arg1:int):DisplayObject{
            if (this.usingBitmap){
                return (this.content.removeChildAt(_arg1));
            };
            return (this.d_removeChildAt(_arg1));
        }
        protected function d_getChildAt(_arg1:int):DisplayObject{
            return (super.getChildAt(_arg1));
        }
        override public function getChildAt(_arg1:int):DisplayObject{
            if (this.usingBitmap){
                return (this.content.getChildAt(_arg1));
            };
            return (this.d_getChildAt(_arg1));
        }
        protected function d_getChildByName(_arg1:String):DisplayObject{
            return (super.getChildByName(_arg1));
        }
        override public function getChildByName(_arg1:String):DisplayObject{
            if (this.usingBitmap){
                return (this.content.getChildByName(_arg1));
            };
            return (this.d_getChildByName(_arg1));
        }
        protected function d_getChildIndex(_arg1:DisplayObject):int{
            return (super.getChildIndex(_arg1));
        }
        override public function getChildIndex(_arg1:DisplayObject):int{
            if (this.usingBitmap){
                return (this.content.getChildIndex(_arg1));
            };
            return (this.d_getChildIndex(_arg1));
        }
        public function containsChild(_arg1:DisplayObject):Boolean{
            if (this.usingBitmap){
                return ((_arg1.parent.parent == this));
            };
            return ((_arg1.parent == this));
        }
        protected function d_setChildIndex(_arg1:DisplayObject, _arg2:int):void{
            super.setChildIndex(_arg1, _arg2);
        }
        override public function setChildIndex(_arg1:DisplayObject, _arg2:int):void{
            if (this.usingBitmap){
                this.content.setChildIndex(_arg1, _arg2);
            } else {
                this.d_setChildIndex(_arg1, _arg2);
            };
        }
        protected function d_swapChildren(_arg1:DisplayObject, _arg2:DisplayObject):void{
            super.swapChildren(_arg1, _arg2);
        }
        override public function swapChildren(_arg1:DisplayObject, _arg2:DisplayObject):void{
            if (this.usingBitmap){
                this.content.swapChildren(_arg1, _arg2);
            } else {
                this.d_swapChildren(_arg1, _arg2);
            };
        }
        protected function d_swapChildrenAt(_arg1:int, _arg2:int):void{
            super.swapChildrenAt(_arg1, _arg2);
        }
        override public function swapChildrenAt(_arg1:int, _arg2:int):void{
            if (this.usingBitmap){
                this.content.swapChildrenAt(_arg1, _arg2);
            } else {
                this.d_swapChildrenAt(_arg1, _arg2);
            };
        }
        protected function get d_numChildren():int{
            return (super.numChildren);
        }
        override public function get numChildren():int{
            if (this.usingBitmap){
                return (this.content.numChildren);
            };
            return (this.d_numChildren);
        }
        override public function addChild(_arg1:DisplayObject):DisplayObject{
            if (this.foregroundChild != null){
                if (this.usingBitmap){
                    return (this.content.addChildAt(_arg1, this.content.getChildIndex(this.foregroundChild)));
                };
                this.d_addChild(_arg1);
                this.d_swapChildren(_arg1, this.foregroundChild);
                return (_arg1);
            };
            if (this.usingBitmap){
                return (this.content.addChild(_arg1));
            };
            return (this.d_addChild(_arg1));
        }
        public function getHighestIndexUnderForeground():int{
            if (this.foregroundChild == null){
                return (this.numChildren);
            };
            return ((this.numChildren - 1));
        }
        public function getLowestIndexAboveBackground():int{
            if (this.backgroundChild == null){
                return (0);
            };
            return (1);
        }
        override public function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean{
            if (((this.isClipMasked()) && (!(_arg3)))){
                return (this.maskShape.hitTestPoint(_arg1, _arg2, _arg3));
            };
            return (super.hitTestPoint(_arg1, _arg2, _arg3));
        }
        override public function hitTestObject(_arg1:DisplayObject):Boolean{
            if (this.isClipMasked()){
                return (this.maskShape.hitTestObject(_arg1));
            };
            return (super.hitTestObject(_arg1));
        }
        public function bringToTop(_arg1:DisplayObject):void{
            var _local2:int = (this.numChildren - 1);
            if (this.foregroundChild != null){
                if (this.foregroundChild != _arg1){
                    _local2 = (this.numChildren - 2);
                };
            };
            this.setChildIndex(_arg1, _local2);
        }
        public function bringToBottom(_arg1:DisplayObject):void{
            var _local2:int;
            if (this.backgroundChild != null){
                if (this.backgroundChild != _arg1){
                    _local2 = 1;
                };
            };
            this.setChildIndex(_arg1, _local2);
        }
        protected function setBackgroundChild(_arg1:DisplayObject=null):void{
            if (_arg1 != this.backgroundChild){
                if (this.backgroundChild != null){
                    this.removeChild(this.backgroundChild);
                };
                this.backgroundChild = _arg1;
                if (_arg1 != null){
                    this.addChildAt(_arg1, 0);
                };
            };
        }
        protected function getBackgroundChild():DisplayObject{
            return (this.backgroundChild);
        }
        protected function setForegroundChild(_arg1:DisplayObject=null):void{
            if (_arg1 != this.foregroundChild){
                if (this.foregroundChild != null){
                    this.removeChild(this.foregroundChild);
                };
                this.foregroundChild = _arg1;
                if (_arg1 != null){
                    this.addChild(_arg1);
                };
            };
        }
        protected function getForegroundChild():DisplayObject{
            return (this.foregroundChild);
        }
        public function setClipMasked(_arg1:Boolean):void{
            if (_arg1 != this.clipMasked){
                this.clipMasked = _arg1;
                this.setUsingBitmap(((cacheAsBitmap) && (this.clipMasked)));
                if (this.clipMasked){
                    this.checkCreateMaskShape();
                    if (this.maskShape.parent != this){
                        this.d_addChild(this.maskShape);
                        this.mask = this.maskShape;
                    };
                    this.setClipMaskRect(this.clipMaskRect);
                } else {
                    if (((!((this.maskShape == null))) && ((this.maskShape.parent == this)))){
                        this.d_removeChild(this.maskShape);
                    };
                    this.mask = null;
                };
            };
        }
        protected function setClipMaskRect(_arg1:IntRectangle):void{
            if (this.maskShape){
                this.maskShape.x = _arg1.x;
                this.maskShape.y = _arg1.y;
                this.maskShape.height = _arg1.height;
                this.maskShape.width = _arg1.width;
            };
            this.clipMaskRect.setRect(_arg1);
        }
        private function setUsingBitmap(_arg1:Boolean):void{
            if (this.usingBitmap != _arg1){
                this.usingBitmap = _arg1;
                this.usingBitmapChanged();
            };
        }
        private function usingBitmapChanged():void{
            var _local1:Array;
            var _local2:int;
            var _local3:int;
            if (this.usingBitmap){
                if (!this.content){
                    this.content = new Sprite();
                    this.content.tabEnabled = false;
                    this.content.mouseEnabled = false;
                };
                _local1 = new Array();
                _local2 = this.d_numChildren;
                _local3 = 0;
                while (_local3 < _local2) {
                    if (this.d_getChildAt(_local3) != this.maskShape){
                        _local1.push(this.d_getChildAt(_local3));
                    };
                    _local3++;
                };
                _local3 = 0;
                while (_local3 < _local1.length) {
                    this.content.addChild(_local1[_local3]);
                    _local3++;
                };
                this.d_addChild(this.content);
                if (this.clipMasked){
                    super.mask = null;
                    this.content.mask = this.maskShape;
                };
            } else {
                this.d_removeChild(this.content);
                _local1 = new Array();
                _local2 = this.content.numChildren;
                _local3 = 0;
                while (_local3 < _local2) {
                    _local1.push(this.content.getChildAt(_local3));
                    _local3++;
                };
                _local3 = 0;
                while (_local3 < _local1.length) {
                    this.d_addChild(_local1[_local3]);
                    _local3++;
                };
                if (this.clipMasked){
                    this.content.mask = null;
                    super.mask = this.maskShape;
                };
            };
        }
        override public function set mask(_arg1:DisplayObject):void{
            if (this.usingBitmap){
                this.content.mask = _arg1;
            } else {
                super.mask = _arg1;
            };
        }
        override public function get mask():DisplayObject{
            if (this.usingBitmap){
                return (this.content.mask);
            };
            return (super.mask);
        }
        override public function set filters(_arg1:Array):void{
            super.filters = _arg1;
            this.setUsingBitmap(((super.cacheAsBitmap) && (this.clipMasked)));
        }
        override public function set cacheAsBitmap(_arg1:Boolean):void{
            super.cacheAsBitmap = _arg1;
            this.setUsingBitmap(((_arg1) && (this.clipMasked)));
        }
        private function checkCreateMaskShape():void{
            if (!this.maskShape){
                this.maskShape = new Shape();
                this.maskShape.graphics.beginFill(0);
                this.maskShape.graphics.drawRect(0, 0, 1, 1);
                this.maskShape.graphics.endFill();
            };
        }
        public function isClipMasked():Boolean{
            return (this.clipMasked);
        }
        private function __awSpriteMouseDownListener(_arg1:MouseEvent):void{
            this.pressedTarget = (_arg1.target as DisplayObject);
            if (stage){
                stage.addEventListener(MouseEvent.MOUSE_UP, this.__awStageMouseUpListener, false, 0, true);
                addEventListener(Event.REMOVED_FROM_STAGE, this.__awStageRemovedFrom);
            };
        }
        private function __awStageRemovedFrom(_arg1:Event):void{
            this.pressedTarget = null;
            stage.removeEventListener(MouseEvent.MOUSE_UP, this.__awStageMouseUpListener);
        }
        private function __awStageMouseUpListener(_arg1:MouseEvent):void{
            if (stage){
                stage.removeEventListener(MouseEvent.MOUSE_UP, this.__awStageMouseUpListener);
            };
            var _local2:Boolean;
            var _local3:DisplayObject = (_arg1.target as DisplayObject);
            if (!(((this == _local3)) || (AsWingUtils.isAncestorDisplayObject(this, _local3)))){
                _local2 = true;
            };
            dispatchEvent(new ReleaseEvent(ReleaseEvent.RELEASE, this.pressedTarget, _local2, _arg1));
            if (_local2){
                dispatchEvent(new ReleaseEvent(ReleaseEvent.RELEASE_OUT_SIDE, this.pressedTarget, _local2, _arg1));
            };
            this.pressedTarget = null;
        }
        override public function toString():String{
            var _local3:String;
            var _local1:DisplayObject = this;
            var _local2:String = _local1.name;
            while (_local1.parent != null) {
                _local3 = ((_local1.parent == _local1.stage)) ? "Stage" : _local1.parent.name;
                _local1 = _local1.parent;
                _local2 = ((_local3 + ".") + _local2);
            };
            return (_local2);
        }

    }
}//package org.aswing 
